<apidoc:module name="OOXML" category="WordProcessingML Support" lib="ooxml" 
	xmlns:apidoc="http://marklogic.com/xdmp/apidoc" 
	xmlns="http://www.w3.org/1999/xhtml"
	bucket="XQuery Library Modules">
  <apidoc:summary>
	  <p>The WordProcessingML function module is included in the 
		  Toolkit for Word&#174; zip package as the following 
		  file:</p>
    <ul>
    <li><code><em>zip_dir</em>/xquery/word-processing-ml-support.xqy</code></li>
    </ul>
    <p>where <code><em>zip_dir</em></code> is the directory in which 
	    the Toolkit for Word was unzipped.</p>
    <p>To use the <code>word-processing-ml-support.xqy</code> module in your 
	    own XQuery modules, copy it to your App Server root and include a 
	    line similar to the following in your XQuery prolog:</p>
    <pre xml:space="preserve">
import module namespace ooxml="http://marklogic.com/openxml" 
   at "/word-processing-ml.xqy";</pre>
    <p>The WordProcessingML functions are used to manipulate Microsoft Office
    Open XML documents.</p>
  </apidoc:summary>
  <apidoc:function name="update-document-xml" lib="ooxml" 
	  category="WordProcessingML Support"  bucket="XQuery Library Modules"
	  hidden="true">
    <apidoc:summary>This function is a helper function.</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="document" type="element(w:document)">Parameter description...</apidoc:param>
    </apidoc:params>
    <apidoc:return>node()*</apidoc:return>
  </apidoc:function>

  <apidoc:function name="passthru" lib="ooxml" category="WordProcessingML Support"
	   bucket="XQuery Library Modules" hidden="true">
	  <apidoc:summary>This function is used by the recursive 
		  dispatch function.</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="x" type="node()*">The node.</apidoc:param>
    </apidoc:params>
    <apidoc:return>node()*</apidoc:return>

  </apidoc:function>
  <apidoc:function name="dispatch" lib="ooxml" category="WordProcessingML Support"
	   bucket="XQuery Library Modules" hidden="true">
	  <apidoc:summary>This function handles the recursive 
		  transformation.</apidoc:summary>
    <apidoc:params>
	    <apidoc:param name="x" type="node()*">The nodes to 
		    transform.</apidoc:param>
    </apidoc:params>
    <apidoc:return>node()*</apidoc:return>

  </apidoc:function>
  <apidoc:function name="mergeruns" lib="ooxml" category="WordProcessingML Support"
	   bucket="XQuery Library Modules" hidden="true">
	  <apidoc:summary>This function merges <code>w:r</code>
		  text runs, which sometimes are broken in arbitrary
		  places.
	  </apidoc:summary>
    <apidoc:params>
	    <apidoc:param name="p" type="element(w:p)">A <code>w:p</code>
		    element whose text runs (<code>w:r</code> elements) 
		    will be merged.</apidoc:param>
    </apidoc:params>
    <apidoc:return>element(w:p)</apidoc:return>
    <apidoc:example><pre xml:space="preserve"><![CDATA[
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml.xqy";
declare namespace w=
	  "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

let $runs := <w:p w:rsidR="00D203FD" w:rsidRDefault="00423AEC">
           <w:r><w:t>This is a de</w:t></w:r>
           <w:r><w:t xml:space="preserve">monstration </w:t></w:r>
            <w:r><w:t>of merging runs</w:t></w:r>
        </w:p>
return	  
ooxml:mergeruns($runs)
=>
<w:p w:rsidR="00D203FD" w:rsidRDefault="00423AEC" 
 xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
 <w:r>
	 <w:t xml:space="preserve">This is a demonstration of merging runs</w:t>
  </w:r>
</w:p>

  ]]></pre>
  </apidoc:example>
  </apidoc:function>
  <apidoc:function name="descend" lib="ooxml" category="WordProcessingML Support"
	   bucket="XQuery Library Modules" hidden="true">
	  <apidoc:summary>This function is used in the recursive descent.
	  </apidoc:summary>
    <apidoc:params>
      <apidoc:param name="r" type="node()?">A node.</apidoc:param>
      <apidoc:param name="rToCheck" type="element(w:rPr)?">An element.
      </apidoc:param>
    </apidoc:params>
    <apidoc:return>element(w:r)*</apidoc:return>

  </apidoc:function>
  <apidoc:function name="map" lib="ooxml" category="WordProcessingML Support"
	   bucket="XQuery Library Modules" hidden="true">
    <apidoc:summary>This function maps.</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="r" type="node()*">The nodes to map.</apidoc:param>
    </apidoc:params>
    <apidoc:return>node()*</apidoc:return>

  </apidoc:function>

  <apidoc:function name="create-paragraph" lib="ooxml" 
	  category="WordProcessingML Support" bucket="XQuery Library Modules">
	  <apidoc:summary>This function creates a <code>w:p</code> element 
		  from the specified string.</apidoc:summary>
    <apidoc:params>
	    <apidoc:param name="para" type="xs:string">The text of the 
		    paragraph.</apidoc:param>
    </apidoc:params>
    <apidoc:return>element(w:p)</apidoc:return>
    <apidoc:example><pre xml:space="preserve"><![CDATA[
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
          at "/MarkLogic/openxml/word-processing-ml.xqy";

ooxml:create-paragraph("Hello there everyone.")

=> 
<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
   <w:r><w:t>Hello there everyone.</w:t></w:r>
</w:p>
  
  ]]></pre>
  </apidoc:example>
  </apidoc:function>
  <apidoc:function name="passthru-para" lib="ooxml" category="WordProcessingML Support"
	  hidden="true" bucket="XQuery Library Modules">
    <apidoc:summary>This function....</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="x" type="node()">Parameter description...</apidoc:param>
    </apidoc:params>
    <apidoc:return>node()*</apidoc:return>

  </apidoc:function>
  <apidoc:function name="dispatch-paragraph-to-clean" lib="ooxml" 
	  category="WordProcessingML Support" hidden="true" 
	  bucket="XQuery Library Modules">
    <apidoc:summary>This function....</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="x" type="node()">Parameter description...</apidoc:param>
    </apidoc:params>
    <apidoc:return>node()?</apidoc:return>

  </apidoc:function>
  <apidoc:function name="remove-paragraph-styles" lib="ooxml" 
	  category="WordProcessingML Support" bucket="XQuery Library Modules">
	  <apidoc:summary>This function removes all properties from 
		  <code>w:p</code> paragraphs. Paragraph properties are 
		  <code>w:pPr</code> elements and run properties are 
		  <code>w:rPr</code> elements.
	  </apidoc:summary>
    <apidoc:params>
	    <apidoc:param name="paragraph" type="element()">Any block-level
	    element.</apidoc:param>
    </apidoc:params>
    <apidoc:return>element()</apidoc:return>
    <apidoc:usage>This function is useful when you want to insert a 
	    paragraph with the Office defaults, or when you want to 
	    switch the existing properties for a paragraph.</apidoc:usage>
    <apidoc:example><pre xml:space="preserve"><![CDATA[
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml.xqy";

let $paragraph:=
<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:pPr><w:b/></w:pPr>
     <w:r><w:rPr><w:u/></w:rPr>
             <w:t>This is a test.</w:t>
      </w:r></w:p>
return ooxml:remove-paragraph-styles($paragraph)
=>
<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
	<w:r><w:t>This is a test.</w:t></w:r>
</w:p>

]]></pre>
  </apidoc:example>
  </apidoc:function>
  <apidoc:function name="get-paragraph-styles" lib="ooxml" 
	  category="WordProcessingML Support" bucket="XQuery Library Modules">
	  <apidoc:summary>This function returns the paragraph 
		  properties.  Returns the empty sequence
		  if no styles are found.</apidoc:summary>
    <apidoc:params>
	    <apidoc:param name="paragraph" type="element(w:p)*">The w:p 
		    element(s).</apidoc:param>
    </apidoc:params>
    <apidoc:return>element(w:pPr)*</apidoc:return>
    <apidoc:example><pre xml:space="preserve"><![CDATA[
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml.xqy";

let $wp := 
<w:p  xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:pPr><w:u/></w:pPr>
  <w:r><w:t>This is a test.</w:t></w:r>
</w:p>
return ooxml:get-paragraph-styles($wp)
=>
<w:pPr xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
	<w:u/>
</w:pPr>
  ]]></pre>
  </apidoc:example>
  </apidoc:function>
  <apidoc:function name="get-run-styles" lib="ooxml" 
	  category="WordProcessingML Support" bucket="XQuery Library Modules">
	  <apidoc:summary>This function returns paragraph run 
		  styles. Returns the empty sequence
		  if no styles are found.</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="paragraph" type="element(w:p)*">The w:p 
		    element(s).</apidoc:param>
    </apidoc:params>
    <apidoc:return>element(w:rPr)*</apidoc:return>
    <apidoc:example><pre xml:space="preserve"><![CDATA[
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml.xqy";


let $wp := 
<w:p  xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:pPr><w:u/></w:pPr>
  <w:r>
      <w:rPr><w:b/></w:rPr>
      <w:t>This is a test.</w:t>
   </w:r>
  <w:r>
      <w:rPr><w:i/></w:rPr>
      <w:t>This is another.</w:t>
   </w:r>
</w:p>
return ooxml:get-run-styles($wp)
=>
<w:rPr xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
	<w:b/>
</w:rPr>
<w:rPr xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
	<w:i/>
</w:rPr>

]]></pre>
  </apidoc:example>
  </apidoc:function>
  <apidoc:function name="get-paragraph-style-id" lib="ooxml" 
	  category="WordProcessingML Support" bucket="XQuery Library Modules">
	  <apidoc:summary>This function returns the @val attribute for
		  a <code>w:pStyle</code> element (child of
		  <code>w:pPr</code>) from $pstyle. Returns the empty sequence
		  if no IDs are found.
	  </apidoc:summary>
    <apidoc:params>
	    <apidoc:param name="pstyle" type="element(w:pPr)">The 
		    <code>w:pPr</code> element.</apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string?</apidoc:return>
    <apidoc:example><pre xml:space="preserve"><![CDATA[
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml.xqy";

declare namespace w=
  "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

let $pstyle:= 
       <w:pPr>
             <w:pStyle w:val="TestParagraphStyle" />
             <w:ind w:left="1440" />
        </w:pPr>
return ooxml:get-paragraph-style-id($pstyle)

=> TestParagraphStyle
]]></pre>
  </apidoc:example>
  </apidoc:function>
  <apidoc:function name="get-run-style-id" lib="ooxml" 
	  category="WordProcessingML Support" bucket="XQuery Library Modules">
	  <apidoc:summary>This function returns the values for the attribute
		  @val for a <code>w:rStyle</code> element (which is a child 
		  of a <code>w:rPr</code> element). Returns the empty sequence
		  if no IDs are found.
	  </apidoc:summary>
    <apidoc:params>
	    <apidoc:param name="rstyle" type="element(w:rPr)">The 
		    <code>w:rPr</code> element 
		    containing the <code>w:rStyle</code> element.
	    </apidoc:param>
      
    </apidoc:params>
    <apidoc:return>xs:string?</apidoc:return>
    <apidoc:example><pre xml:space="preserve"><![CDATA[
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml.xqy";

let $rstyle := 
<w:rPr xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
        <w:rStyle w:val="oslo"/><w:u/>
</w:rPr>
return ooxml:get-run-style-id($rstyle)
=>
oslo
]]></pre>
  </apidoc:example>
  </apidoc:function>
  <apidoc:function name="get-style-definition" lib="ooxml" 
	  category="WordProcessingML Support" bucket="XQuery Library Modules">
	  <apidoc:summary>This function returns the style definition from 
		  styles.xml for the given style ID.
	  </apidoc:summary>
    <apidoc:params>
      <apidoc:param name="styleid" type="xs:string">The style ID.</apidoc:param>
      <apidoc:param name="styles" type="element(w:styles)">The root
	      element from the styles.xml file in the .docx 
	      package.
      </apidoc:param>
    </apidoc:params>
    <apidoc:return>element(w:style)?</apidoc:return>
    <apidoc:example><pre xml:space="preserve"><![CDATA[
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml.xqy";
declare namespace w=
  "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

let $styleids := "oslo"
let $styles := doc("/Test_docx_parts/word/styles.xml") 
return ooxml:get-style-definitions($styleids, $styles)/w:style
=>
<w:style xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
       	w:type="character" w:customStyle="1" w:styleId="oslo">
     <w:name w:val="oslo"/><w:basedOn w:val="Emphasis"/>
     <w:uiPriority w:val="1"/><w:qFormat/><w:rsid w:val="005B2E7B"/>
       <w:rPr><w:rFonts w:ascii="Bodoni MT Black" w:hAnsi="Bodoni MT Black"/>
       <w:b/><w:sz w:val="32"/></w:rPr>
</w:style>

]]></pre>
  </apidoc:example>
  </apidoc:function>
  <apidoc:function name="replace-style-definition" lib="ooxml" 
	  category="WordProcessingML Support" bucket="XQuery Library Modules">
	  <apidoc:summary>This function replaces <code>w:style</code> 
		  elements (style definitions) in <code>w:styles</code> 
		  (the styles.xml file from a .docx package).</apidoc:summary>
    <apidoc:params>
	    <apidoc:param name="newstyle" type="element(w:style)">The new style
	    element.</apidoc:param>
    <apidoc:param name="styles" type="element(w:styles)">The old styles 
	    element (from styles.xml).</apidoc:param>
    </apidoc:params>
    <apidoc:return>element(w:styles)</apidoc:return>
    <apidoc:usage>
      <p>If the id for the style $newstyle matches a style definition already 
	      present in $styles, the $newstyle will replace the existing 
	      style.</p>
      <p>If the id for the style $newstyle does not exist in $styles, the 
	      $newstyle definition will be appended to the other 
	      definitions in $styles.</p>
      <p>Note that it is possible within Microsoft Word to create styles 
	      with names that differ only in their case that have different 
	      style attributes. For example,
	      you can create two styles: "mystyle" and "MYSTYLE", which
	      have completely different style definitions.</p>
	    
    </apidoc:usage>
    <apidoc:example><pre xml:space="preserve"><![CDATA[
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml.xqy";

let $oldstyle := 
 <w:styles 
  xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:style w:type="character" w:customStyle="1" w:styleId="oslo">
     <w:name w:val="oslo"/><w:basedOn w:val="Emphasis"/>
     <w:uiPriority w:val="1"/><w:qFormat/><w:rsid w:val="005B2E7B"/>
       <w:rPr><w:rFonts w:ascii="Bodoni MT Black" w:hAnsi="Bodoni MT Black"/>
       <w:b/><w:sz w:val="32"/></w:rPr>
   </w:style>
 </w:styles>
let $newstyle :=
  <w:style 
   xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
   w:type="character" w:customStyle="1" w:styleId="oslo">
     <w:name w:val="oslo"/><w:basedOn w:val="Emphasis"/>
     <w:uiPriority w:val="1"/><w:qFormat/><w:rsid w:val="005B2E7B"/>
       <w:rPr><w:rFonts w:ascii="Courier New" w:hAnsi="Courier New"/>
       <w:b/><w:sz w:val="32"/></w:rPr>
   </w:style>
return
ooxml:replace-style-definition($newstyle, $oldstyle)
=>
<w:styles 
  xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:style w:type="character" w:customStyle="1" w:styleId="oslo">
    <w:name w:val="oslo"/><w:basedOn w:val="Emphasis"/>
    <w:uiPriority w:val="1"/><w:qFormat/><w:rsid w:val="005B2E7B"/>
    <w:rPr><w:rFonts w:ascii="Courier New" w:hAnsi="Courier New"/>
      <w:b/>
      <w:sz w:val="32"/>
    </w:rPr>
  </w:style>
</w:styles>
]]></pre>
  </apidoc:example>
  </apidoc:function>
  <apidoc:function name="set-paragraph-styles-passthru" lib="ooxml" 
	  category="WordProcessingML Support"  bucket="XQuery Library Modules"
	  hidden="true">
    <apidoc:summary>This function is a helper function.</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="x" type="node()*">The nodes.</apidoc:param>
      <apidoc:param name="props" type="element()?">The element.</apidoc:param>
      <apidoc:param name="type" type="xs:string">The type.</apidoc:param>
    </apidoc:params>
    <apidoc:return>node()*</apidoc:return>

  </apidoc:function>
  <apidoc:function name="set-paragraph-styles-dispatch" lib="ooxml" 
	  category="WordProcessingML Support"  bucket="XQuery Library Modules"
	  hidden="true">
    <apidoc:summary>This function  is a helper function.</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="wp" type="node()*">Parameter description...</apidoc:param>
      <apidoc:param name="props" type="element()?">Parameter description...</apidoc:param>
      <apidoc:param name="type" type="xs:string">Parameter description...</apidoc:param>
    </apidoc:params>
    <apidoc:return>node()*</apidoc:return>

  </apidoc:function>
  <apidoc:function name="add-run-style-properties" lib="ooxml" 
	  category="WordProcessingML Support"  bucket="XQuery Library Modules"
	  hidden="true">
    <apidoc:summary>This function is a helper function.</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="wr" type="node()">Parameter description...</apidoc:param>
      <apidoc:param name="runprops" type="element(w:rPr)?">Parameter description...</apidoc:param>
    </apidoc:params>
    <apidoc:return>node()*</apidoc:return>

  </apidoc:function>
  <apidoc:function name="add-paragraph-properties" lib="ooxml" 
	  category="WordProcessingML Support"  bucket="XQuery Library Modules"
	  hidden="true">
    <apidoc:summary>This function is a helper function.</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="wp" type="node()*">Parameter description...</apidoc:param>
      <apidoc:param name="paraprops" type="element(w:pPr)?">Parameter description...</apidoc:param>
      <apidoc:param name="type" type="xs:string">Parameter description...</apidoc:param>
    </apidoc:params>
    <apidoc:return>node()*</apidoc:return>
 
  </apidoc:function>
  <apidoc:function name="replace-paragraph-styles" lib="ooxml" 
	  category="WordProcessingML Support"  bucket="XQuery Library Modules">
	  <apidoc:summary>This function sets paragraph properties for 
		  paragraphs (<code>w:p</code>) within a 
		  block.  If the empty sequence is passed for $wpProps, then
		  the paragraph properties for the $block are
		  removed.</apidoc:summary>
    <apidoc:params>
	    <apidoc:param name="block" type="element()">The block containing 
		    the paragraph to be updated.
	    </apidoc:param>
	    <apidoc:param name="wpProps" type="element(w:pPr)?">The paragraph
		    properties, as a w:pPr element, to be applied within the
		    paragraph block. 
	    </apidoc:param>
    </apidoc:params>
    <apidoc:return>element()</apidoc:return>
    <apidoc:usage>
	    <p>If $block already has styles applied, these styles are replaced 
		    by the new style parameters.  If the empty sequence is 
		    passed for $wpProps, the paragraph properties for the 
		    $block are removed.  If there are no properties currently 
		    defined for the paragraph, the $wpProps are applied.</p>
	    <p>
	    Note that this function does not validate that the 
	    <code>w:pPr</code> element passed in is valid, so make sure the
	    element you pass in is valid WordProcessingML markup.  If you pass
	    in an invalid element, it could result in a document that
	    cannot be opened in Microsoft Word.
	    </p>
	    
    </apidoc:usage>
    <apidoc:example><pre xml:space="preserve"><![CDATA[
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml.xqy";
declare namespace w=
  "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

let $wp1 := 
<w:p>
     <w:r><w:t>THIS IS A TEST!</w:t></w:r>
</w:p>
let $pPr := <w:pPr><w:b/></w:pPr>
return  ooxml:replace-paragraph-styles($wp1,$pPr)
=>
<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
	<w:pPr>
		<w:b/>
        </w:pPr>
	<w:t>THIS IS A TEST!</w:t>
</w:p>

]]></pre>
  </apidoc:example>

  </apidoc:function>
  <apidoc:function name="replace-run-styles" lib="ooxml" 
	  category="WordProcessingML Support" bucket="XQuery Library Modules">
	  <apidoc:summary>This function sets run properties for 
		  runs (<code>w:r</code>) within a 
		  block.  If the empty sequence is passed for $wrProps, then
		  the paragraph properties for the $block are
		  removed.</apidoc:summary>
    <apidoc:params>
	    <apidoc:param name="block" type="element()">The block containing 
		    the run to be updated.
	    </apidoc:param>
	    <apidoc:param name="wrProps" type="element(w:rPr)?">The run
		    properties, as a w:rPr element, to be applied within the
		    run block. 
	    </apidoc:param>
    </apidoc:params>
    <apidoc:return>element()</apidoc:return>
    <apidoc:usage>
	    Note that this function does not validate that the 
	    <code>w:rPr</code> element passed in is valid, so make sure the
	    element you pass in is valid WordProcessingML markup.  If you pass
	    in an invalid element, it could result in a document that
	    cannot be opened in Microsoft Word.
    </apidoc:usage>
    <apidoc:example><pre xml:space="preserve"><![CDATA[
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml.xqy";
declare namespace w=
  "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

let $wp1 := 
<w:p>
     <w:r><w:t>THIS IS A TEST!</w:t></w:r>
</w:p>
let $rPr := <w:rPr><w:b/></w:rPr>
return  ooxml:replace-run-styles($wp1,$rPr)
=>
<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:r>
    <w:rPr>
      <w:b/>
    </w:rPr>
    <w:t>THIS IS A TEST!</w:t>
  </w:r>
</w:p>	

]]></pre>
  </apidoc:example>

  </apidoc:function>
  <apidoc:function name="set-paragraph-styles" lib="ooxml" 
	  category="WordProcessingML Support" bucket="XQuery Library Modules"
	  hidden="true">
    <apidoc:summary>This function is a helper function.</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="wp" type="node()*">Parameter description...</apidoc:param>
      <apidoc:param name="wpProps" type="element(w:pPr)?">Parameter description...</apidoc:param>
      <apidoc:param name="wrProps" type="element(w:rPr)?">Parameter description...</apidoc:param>
    </apidoc:params>
    <apidoc:return>node()*</apidoc:return>

  </apidoc:function>
  <apidoc:function name="custom-xml" lib="ooxml" category="WordProcessingML Support"
	   bucket="XQuery Library Modules">
	  <apidoc:summary>This function tags $content with 
		  <code>w:customXml</code> and sets the @element value
		  to $tag.
	  </apidoc:summary>
    <apidoc:params>
	    <apidoc:param name="content" type="element()">The content 
		    element.</apidoc:param>
	    <apidoc:param name="tag" type="xs:string">The name of the 
		    custom XML tag.</apidoc:param>
    </apidoc:params>
    <apidoc:return>element(w:customXml)?</apidoc:return>
    <apidoc:usage>The $content parameter must either be an element of type 
	    paragraph (w:p) , run (w:r), field (w:fldSimple,w:fldChar), 
	    hyperlink (w:hyperlink), custom xml (w:customXml), structured 
	    document tag (w:sdt), table (w:tbl), cel (w:tc), or row (w:tr).  
	    If it is not one of these types, the function 
	    returns the empty sequence.</apidoc:usage>
    <apidoc:example><pre xml:space="preserve"><![CDATA[
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml.xqy";

let $para:= 
  <w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
       <w:r><w:t>This is my paragraph.</w:t></w:r>
  </w:p>
let $tag := "ABCD"
return ooxml:custom-xml($para,$tag)
=>
<w:customXml w:element="ABCD" 
  xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:p><w:r><w:t>This is my paragraph.</w:t></w:r></w:p>
</w:customXml>
]]></pre>
  </apidoc:example>
  </apidoc:function>
  <apidoc:function name="set-custom-xml-passthru" lib="ooxml" 
	  category="WordProcessingML Support" bucket="XQuery Library Modules"
	  hidden="true">
    <apidoc:summary>This function is a helper function.</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="x" type="node()*">Parameter description...</apidoc:param>
      <apidoc:param name="oldtag" type="xs:string">Parameter description...</apidoc:param>
      <apidoc:param name="newtag" type="xs:string">Parameter description...</apidoc:param>
    </apidoc:params>
    <apidoc:return>node()*</apidoc:return>
 
  </apidoc:function>
  <apidoc:function name="set-custom-xml-dispatch" lib="ooxml" 
	  category="WordProcessingML Support" bucket="XQuery Library Modules"
	  hidden="true">
    <apidoc:summary>This function is a helper function.</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="block" type="node()*">Parameter description...</apidoc:param>
      <apidoc:param name="oldtag" type="xs:string">Parameter description...</apidoc:param>
      <apidoc:param name="newtag" type="xs:string">Parameter description...</apidoc:param>
    </apidoc:params>
    <apidoc:return>node()*</apidoc:return>

  </apidoc:function>
  <apidoc:function name="set-custom-element-value" lib="ooxml" 
	  category="WordProcessingML Support" bucket="XQuery Library Modules"
	  hidden="true">
    <apidoc:summary>This function is a helper function.</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="block" type="node()*">Parameter description...</apidoc:param>
      <apidoc:param name="oldtag" type="xs:string">Parameter description...</apidoc:param>
      <apidoc:param name="newtag" type="xs:string">Parameter description...</apidoc:param>
    </apidoc:params>
    <apidoc:return>node()*</apidoc:return>
  </apidoc:function>

  <apidoc:function name="replace-custom-xml-element" lib="ooxml" 
	  category="WordProcessingML Support" bucket="XQuery Library Modules">
	  <apidoc:summary>This function replaces any @element values for 
		  <code>w:customXml</code> with $newtag, where 
		  <code>w:customXml[@w:element = $oldtag]</code>.
	  </apidoc:summary>
    <apidoc:params>
	    <apidoc:param name="content" type="element()">The OOXML 
		    content.</apidoc:param>
      <apidoc:param name="oldtag" type="xs:string">The old tag for the 
	      element name.</apidoc:param>
      <apidoc:param name="newtag" type="xs:string">The new tag for the 
	      element name.</apidoc:param>
    </apidoc:params>
    <apidoc:return>element()</apidoc:return>
    <apidoc:example><pre xml:space="preserve"><![CDATA[
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml.xqy";

declare namespace w=
  "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

let $block:=
<w:customXml w:element="ABCD">
    <w:p>
<w:r><w:t>This is my paragraph.</w:t></w:r>
         </w:p>
</w:customXml>
let $origtag := "ABCD"
let $newtag := "EFGH"
return ooxml:replace-custom-xml-element($block,$origtag,$newtag)
=>
<w:customXml w:element="EFGH" 
  xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:p><w:r><w:t>This is my paragraph.</w:t></w:r></w:p>
</w:customXml>
]]></pre>
  </apidoc:example>
  </apidoc:function>
  <apidoc:function name="get-custom-xml-ancestor" lib="ooxml" 
	  category="WordProcessingML Support" bucket="XQuery Library Modules">
	  <apidoc:summary>This function returns the greatest ancestor of the 
		  specified node that is either an immediate parent of 
		  type <code>w:customXml</code> or <code>w:sdt</code>, a
		  parent of that parent, and so on until the parent is not
		  a <code>w:customXml</code> or <code>w:sdt</code>
		  element.  If no such ancestor is found, then the empty 
		  sequence is returned.
	  </apidoc:summary>
    <apidoc:params>
	    <apidoc:param name="doc" type="element()">An element to 
		    search.</apidoc:param>
    </apidoc:params>
    <apidoc:return>element()?</apidoc:return>
    <apidoc:example><pre xml:space="preserve"><![CDATA[
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml.xqy";
declare namespace w=
  "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

let $para:= 
 <w:p>
   <w:r><w:t>THIS IS A TEST!</w:t></w:r>
 </w:p>
let $custom := 
  <w:customXml w:element="foo">
    <w:customXml w:element="bar">{$para}</w:customXml>
  </w:customXml>
let $wp1 := $custom//w:p
return  ooxml:get-custom-xml-ancestor($wp1)
=>
<w:customXml w:element="foo" 
  xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
 <w:customXml w:element="bar">
	<w:p><w:r><w:t>THIS IS A TEST!</w:t></w:r></w:p>
 </w:customXml>
</w:customXml>


  ]]></pre>
  </apidoc:example>
  </apidoc:function>

  <apidoc:function name="paragraph-search" lib="ooxml" 
	  category="WordProcessingML Support" bucket="XQuery Library Modules"
	  hidden="true">
    <apidoc:summary>This function is a helper function.</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="query" type="cts:query">Parameter description...</apidoc:param>
      <apidoc:param name="begin" type="xs:integer">Parameter description...</apidoc:param>
      <apidoc:param name="end" type="xs:integer">Parameter description...</apidoc:param>
    </apidoc:params>
    <apidoc:return>node()*</apidoc:return>

  </apidoc:function>

  <apidoc:function name="custom-search-all" lib="ooxml" 
	  category="WordProcessingML Support" bucket="XQuery Library Modules"
	  hidden="true">
    <apidoc:summary>This function is a helper function.</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="query" type="cts:query">Parameter description...</apidoc:param>
      <apidoc:param name="begin" type="xs:integer">Parameter description...</apidoc:param>
      <apidoc:param name="end" type="xs:integer">Parameter description...</apidoc:param>
    </apidoc:params>
    <apidoc:return>node()*</apidoc:return>
 
  </apidoc:function>

  <apidoc:function name="passthru-chlt" lib="ooxml" 
	  category="WordProcessingML Support" bucket="XQuery Library Modules"
	  hidden="true">
    <apidoc:summary>This function is a helper function.</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="x" type="node()*">Parameter description...</apidoc:param>
    </apidoc:params>
    <apidoc:return>node()*</apidoc:return>
  
  </apidoc:function>

  <apidoc:function name="map" lib="ooxml" category="WordProcessingML Support"
	   bucket="XQuery Library Modules" hidden="true">
    <apidoc:summary>This function is a helper function.</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="props" type="node()*">Parameter description...</apidoc:param>
      <apidoc:param name="x" type="node()*">Parameter description...</apidoc:param>
    </apidoc:params>
    <apidoc:return>node()*</apidoc:return>
 
  </apidoc:function>

  <apidoc:function name="dispatch-chlt" lib="ooxml" category="WordProcessingML Support"
	  hidden="true" bucket="XQuery Library Modules">
    <apidoc:summary>This function is a helper function.</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="x" type="node()*">Parameter description...</apidoc:param>
    </apidoc:params>
    <apidoc:return>node()*</apidoc:return>
 
  </apidoc:function>

  <apidoc:function name="makerun" lib="ooxml" category="WordProcessingML Support"
	  hidden="true" bucket="XQuery Library Modules">
    <apidoc:summary>This function is a helper function.</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="x" type="text()">Parameter description...</apidoc:param>
      <apidoc:param name="runProps" type="element(w:rPr)">Parameter description...</apidoc:param>
    </apidoc:params>
    <apidoc:return>element(w:r)</apidoc:return>
 
  </apidoc:function>

  <apidoc:function name="custom-xml-highlight-exec" lib="ooxml" 
	  category="WordProcessingML Support" hidden="true" 
	  bucket="XQuery Library Modules">
    <apidoc:summary>This function is a helper function.</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="orig" type="node()*">Parameter description...</apidoc:param>
      <apidoc:param name="query" type="cts:query">Parameter description...</apidoc:param>
      <apidoc:param name="tagname" type="xs:string">Parameter description...</apidoc:param>
      <apidoc:param name="attrs" type="xs:string*">Parameter description...</apidoc:param>
      <apidoc:param name="vals" type="xs:string*">Parameter description...</apidoc:param>
    </apidoc:params>
    <apidoc:return>node()*</apidoc:return>

  </apidoc:function>

  <apidoc:function name="custom-xml-highlight" lib="ooxml" 
	  category="WordProcessingML Support" bucket="XQuery Library Modules">
	  <apidoc:summary>This function highlights $hightlight-term in $nodes 
		  by applying <![CDATA[<w:customXml w:element={$tag-name}>]]>
		  to the term. It searches for term within 
		  <code>w:t</code> elements within a <code>w:r</code> 
		  (runs), wrapping a customXml element around the element
		  the element containing the highlighted match.
	  </apidoc:summary>
    <apidoc:params>
	    <apidoc:param name="nodes" type="node()*">The paragraph(s) from 
		    which to search for the highlighted terms.
	    </apidoc:param>
	    <apidoc:param name="highlight-term" type="cts:query">The 
		    <code>cts:query</code> used to find the 
		    highlight term.</apidoc:param>
	    <apidoc:param name="tag-name" type="xs:string">The
		    name used for the <code>w:customXml w:element</code> 
		    attribute value.</apidoc:param>
	    <apidoc:param name="attributes" type="xs:string*" optional="true">
		    A list of attributes to be added to the
		    <code>w:customXml</code> properties.
	    </apidoc:param>
	    <apidoc:param name="values" type="xs:string*" optional="true">
		    The values corresponding to the $attributes.
	    </apidoc:param>
    </apidoc:params>
    <apidoc:return>node()*</apidoc:return>
    <apidoc:usage>
	    If you specify the $attributes and $values parameters, the length 
	    of the list for each parameter must be the same, otherwise an
	    exception is thrown.
    </apidoc:usage>
    <apidoc:example><pre xml:space="preserve"><![CDATA[
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml.xqy";

declare namespace w=
  "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

let $wp := <w:p><w:r><w:t>THIS IS A TEST!</w:t></w:r></w:p>
let $wordquery := cts:word-query("TEST")
return  ooxml:custom-xml-highlight($wp,$wordquery,"MYTAG")
=>
<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:r>
    <w:t xml:space="preserve">THIS IS A </w:t>
  </w:r>
  <w:customXml w:element="MYTAG">
   <w:r>
     <w:t>TEST</w:t>
   </w:r>
  </w:customXml>
  <w:r>
    <w:t xml:space="preserve">!</w:t>
  </w:r>
</w:p>
  
]]></pre>
  </apidoc:example>
      <apidoc:example><pre xml:space="preserve"><![CDATA[
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml.xqy";

declare namespace w=
  "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

let $wp := <w:p><w:r><w:t>THIS IS A TEST!</w:t></w:r></w:p>
let $wordquery := cts:word-query("TEST")
let $attributes := ("author","id")
let $values := ("oslo","1") 
return  ooxml:custom-xml-highlight($wp,$wordquery,"MYTAG", $attributes, $values)
=>
<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:r>
    <w:t xml:space="preserve">THIS IS A </w:t>
  </w:r>
  <w:customXml w:element="MYTAG">
    <w:customXmlPr>
      <w:attr w:name="author" w:val="oslo"/>
      <w:attr w:name="id" w:val="1"/>
    </w:customXmlPr>
    <w:r>
      <w:t>TEST</w:t>
    </w:r>
  </w:customXml>
  <w:r>
    <w:t xml:space="preserve">!</w:t>
  </w:r>
</w:p>
  
]]></pre>
  </apidoc:example>
  </apidoc:function>

</apidoc:module>
